package com.rainng.coursesystem.module.custom.service.impl;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.rainng.coursesystem.base.utils.BeanMapper;
import com.rainng.coursesystem.module.custom.dto.request.CustomUserReqDTO;
import com.rainng.coursesystem.module.custom.entity.CustomUser;
import com.rainng.coursesystem.module.custom.mapper.CustomUserMapper;
import com.rainng.coursesystem.module.custom.service.CustomUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

@Service
public class CustomUserServiceImpl extends ServiceImpl<CustomUserMapper, CustomUser> implements CustomUserService {
    @Override
    public void save(CustomUserReqDTO reqDTO) {
        CustomUser customUser = new CustomUser();
        BeanMapper.copy(reqDTO,customUser);
        if (StringUtils.isEmpty(customUser.getId())){
            customUser.setId(IdWorker.getIdStr());
            this.save(customUser);
        }else {
            this.updateById(customUser);
        }
    }

}
